# Create your views here.
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext 
from lab.accounts.models import RegisterForm
from django.contrib.auth.models import User
from django.core.mail import mail_admins

def register_form(request):
    if request.POST:
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            username = register_form.data['username']
            email = register_form.data['email']
            password = register_form.data['password']
            user = User.objects.create_user(username, email, password)
            user.is_active = False
            user.save()
            mail_admins('new user register', username)
            return HttpResponseRedirect('/accounts/register_confirm/')
    else:
        register_form = RegisterForm()

    return render_to_response('accounts/register_form.html',{'form':register_form}, context_instance=RequestContext(request))
        
